var app;
var url;
var headers;
Page({
  data:{
    info:[],
    peer_num:0,
    select_num:0,
    isselect:[],
    check_info:[],
    url:"https://app1.sztravel.com.cn/file/weixinapp/img"
  },
  checkgroup:function(e){
    console.log(e);
    var idx= e.detail.value;
    var info=this.data.info;
    var arr=[];
    for(let i=0;i<idx.length;i++){
      arr.push(info[parseInt(idx[i])])
    }
    this.setData({
      check_info: arr,
      select_num:arr.length
    })
  },
  changeTourist:function(e){
    var peerid=e.currentTarget.dataset.peerid;
    wx.navigateTo({
      url:'../add_tourist/add_tourist?touristid='+peerid+'',
    })
  },
  // select(e){
  //   console.log(e)
  //   var index = e.target.dataset.i;
  //   var cdata = this.data.isselect; 
  //   cdata[index] = !cdata[index]
  //   this.setData({
  //     isselect:cdata
  //   })
  //   console.log(this.data.isselect[index])
  //   var selected = this.data.selected;
  //   if(this.data.isselect[index]){
  //     selected[index] = this.data.tourist[index]
  //     selected.length = selected.length+1
  //   }else{
  //     delete selected[index];
  //     selected.length = selected.length-1
  //   }
  //   this.setData({
  //     selected:selected
  //   })
  //   console.log(this.data.selected)
  // },
  select_over:function(){
    var that=this;
    var peer_num=this.data.peer_num;
    var select_num = this.data.select_num;
    var check_info = this.data.check_info;
    if (select_num < peer_num){
      wx.showToast({
        title: '游客数量不足',
      },1500)
    } else if (select_num > peer_num){
      wx.showToast({
        title: '选择的游客太多啦~',
      })
    }else if (select_num == peer_num){
      try{
        wx.setStorageSync('check_info', JSON.stringify(check_info));
        wx.navigateBack({
          delta:1
        })
      }catch(e){

      }
    }
  },
  edit(){
    wx.navigateTo({
      url: '../add_tourist/add_tourist',
    })     
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
    var that = this;
    app = getApp();
    url = app.globalData.url;
    headers = app.globalData.headers;
    try{
      var test_info = JSON.parse(wx.getStorageSync("test_info"));
      that.setData({
        peer_num: parseInt(test_info.total_num)
      })
    }catch(e){

    };  
    wx.request({
      url: url +'api/get_my_peer_list',
      method:"POST",
      header:headers,
      success:function(data){
        console.log(data)
        if(data.data.result===1){
          that.setData({
            info: data.data.data.peer_list    
          })
          console.log(that.data)
        }else{
          wx.showModal({
            title: '来自伴行的提示',
            content: data.data.message,
          })
        }
      }
    })
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  }
})